package hash;

import java.util.HashMap;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/8/20
 */
public class FourNumSum {

    public static void main(String[] args) {
        int res = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] a = new int[] {1, 2};
        int[] b = new int[] {-2,-1};
        int[] c = new int[] {-1, 2};
        int[] d = new int[] { 0, 2};

        for (int i : a) {
            for (int j : b) {
                int sum = i + j;
                map.put(sum, map.getOrDefault(sum, 0) + 1);
            }
        }

        for (int m: c) {
            for (int n : d) {
                int sum = m+n;
                int target = -sum;
                Integer count = map.getOrDefault(target, 0);
                res+=count;
            }
        }

        System.out.println(res);
    }
}
